package wusiyuan.dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;

import util.C3P0Util;
import wusiyuan.dao.SetThedefaultAddressDao;

public class SetThedefaultAddressDaoImpl implements SetThedefaultAddressDao {

	@Override
	public Integer SetThedefaultAddress(Integer userId,Integer user_addr_id) {
		Integer i=0;
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());	
		
		String sql="UPDATE user_addr SET is_default = 1 WHERE  userId = ?  AND user_addr_id = ? ";		
		Object[] pram ={userId,user_addr_id};		
		try {
			i = qr.update(sql, pram);
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		return i;
	}

	@Override
	public Integer SetTheOtherAddress(Integer userId, Integer user_addr_id) {
		Integer i=0;
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());	
		String sql="UPDATE user_addr SET is_default =0 WHERE  userId = ?  AND user_addr_id != ? ";
		Object[] pram ={userId,user_addr_id};		
		try {
			i = qr.update(sql, pram);
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		return i;
	}

}
